<?php
require_once(t3lib_extMgm::extPath('univis2typo3').'/mod1/parser/univis2mysql.php');
require_once(t3lib_extMgm::extPath('univis2typo3').'/mod1/progressbar/class.progressbar.php');
require_once(t3lib_extMgm::extPath('univis2typo3').'/mod1/parser/sql/class.univistablemanager.php');
require_once(t3lib_extMgm::extPath('univis2typo3').'/mod1/parser/sql/class.univistablemanager_createtx.php');
require_once(t3lib_extMgm::extPath('univis2typo3').'/mod1/parser/sql/class.filltxtables.php');
	
class tx_univis2typo3_updater extends tx_scheduler_Task {
	public function execute() {
		ini_set('max_execution_timeout', 600);

		$conf = array();
		$conf['parser']['tempfolder'] = '';
		$conf['parser']['runAsTask'] = true; // If this is set, don't use interactive features

		// UnivIS Configuration
		$conf['univis']['department'] = '100105'; // UnvIS department ID (100106 = Inf2, 100105 = Inf5)
		//$this->conf['univis']['department'] = '090106'; // UnvIS department ID (100106 = Inf2, 100105 = Inf5)
		$conf['univis']['server'] = 'univis.uni-erlangen.de';
		$conf['univis']['prg_url'] = 'http://'.$conf['univis']['server'].'/prg?';


		// what data to import from UnivIS
		$conf['univis']['modules'] = array(
			'lectures' => true,
			'persons' => true,
			'chapters' => false,
			'departments' => true,
			'calendar' => false,
			'rooms' => true,
			'thesis' => true,
			'publications' => true,
			'projects' => true,
		);

		$conf['ProgressBar'] = new ProgressBar('#ffffff', false);

		$univistablemanager = new UnivisTableManager();
		$TX_univistablemanager = new UnivisTableManager_createtx();
		$fillTXTables = new FillTXTables();

		
		$conf['ProgressBar']->setUpdateInfo('Deleting u_ tables.');
		$univistablemanager->delete_db_data();

		$conf['ProgressBar']->setUpdateInfo('Updating data from UnivIS for department ID ' . $conf['univis']['department'] . '.');
		updateFromUnivis($conf);

		$conf['ProgressBar']->nextStep();


		// copy data to tx_ tables
		$conf['ProgressBar']->setUpdateInfo('Deleting tx_ tables.');
		$TX_univistablemanager->delete_db_data();

		$conf['ProgressBar']->setUpdateInfo('Updating tx_ tables.');
		$fillTXTables->copyTables();
		
		return true;
	}
}
?>
